﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using NFinal.Action;

namespace NFinal.ActionResults
{
    public class FileContentResult : FileResult
    {
        public byte[] FileContents { get; set; }
        public FileContentResult(byte[] fileContents, string contentType) :base(contentType)
        {
            if (fileContents==null)
            {
                throw new ArgumentNullException(nameof(fileContents));
            }
            this.FileContents = fileContents;
        }
        public override async Task ExecuteResultAsync<TContext, TRequest>(AbstractAction<TContext, TRequest> context)
        {
            context.SetResponseHeader(Constant.HeaderContentType, this.ContentType);
            await context.WriteAsync(FileContents);
        }
    }
}
